package com.xuecheng.comment.agent.hystrix;

import com.xuecheng.api.content.model.dto.CoursePubDTO;
import com.xuecheng.comment.agent.CoursePubApiAgent;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.hystrix.BaseAPIHystrix;
import com.xuecheng.common.hystrix.BaseFallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2021/04/05/19:53 周一
 *
 * @author Lantin
 */

@Component
public class CoursePubApiAgentFallbackFactory extends BaseFallbackFactory<
        BaseAPIHystrix<CoursePubDTO>,
        CoursePubApiAgentFallbackFactory.CoursePubApiAgentHystrix,
        CoursePubApiAgentFallbackFactory.DevCoursePubApiAgentHystrix> {

    /**
     * <p>
     * 生产环境降级方法类
     * </p>
     * 返回
     */
   public static class CoursePubApiAgentHystrix extends BaseAPIHystrix<CoursePubDTO> implements CoursePubApiAgent {


        public CoursePubApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<CoursePubDTO> getCoursePubById(Long mediaId) {
            return baseFailResult();
        }

        @Override
        public RestResponse<List<CoursePubDTO>> getCoursePubByCompanyId(Long companyId) {
            return null;
        }
    }

    /**
     * <p>
     * 开发环境降级方法类
     * </p>
     * 返回一个默认值
     */
    public static class DevCoursePubApiAgentHystrix extends BaseAPIHystrix<CoursePubDTO> implements CoursePubApiAgent {

        public DevCoursePubApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }
        @Override
        public RestResponse<CoursePubDTO> getCoursePubById(Long mediaId) {
           return RestResponse.success(new CoursePubDTO());
        }

        @Override
        public RestResponse<List<CoursePubDTO>> getCoursePubByCompanyId(Long companyId) {
            return RestResponse.success(new ArrayList<>());
        }
    }
}
